package com.motong.gongdan.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.motong.gongdan.entity.ReportBadProduct;
import com.motong.gongdan.entity.WorkReport;
import com.motong.gongdan.vo.H5Resp.*;
import com.motong.gongdan.vo.H5Vo.Dashboard.query.BadProductDistributedQuery;
import com.motong.gongdan.vo.H5Vo.Dashboard.query.GetAllQuery;
import com.motong.gongdan.vo.H5Vo.Dashboard.query.WorkerRankDetailQuery;
import com.motong.gongdan.vo.H5Vo.Dashboard.vo.BadProductRateStatisticsVo;
import com.motong.gongdan.vo.H5Vo.Dashboard.vo.BroadcastVo;
import com.motong.gongdan.vo.H5Vo.Dashboard.vo.WorkReportStatisticsVo;
import com.motong.gongdan.vo.H5Vo.common.GroupCountVo;
import com.motong.gongdan.vo.resp.*;
import com.motong.gongdan.vo.system.DataBoard.query.WorkReportGroupByProcessQuery;
import com.motong.gongdan.vo.system.DataBoard.vo.ReportGroupProcessInfo;
import com.motong.gongdan.vo.system.DataBoard.vo.WorkReportDetailVo;
import com.motong.gongdan.vo.system.otherVo.ProduceReportListVo;
import com.motong.gongdan.vo.system.otherVo.WorkReportListVo;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface WorkReportMapper extends BaseMapper<WorkReport> {
    IPage<WorkReportListResp> getList(Page page, @Param("workOrderCode") String workOrderCode, @Param("productCode") String productCode, @Param("productName") String productName,
                                      @Param("productSpecification") String productSpecification, @Param("userIds") List<String> userIds,
                                      @Param("processState") List<String> processState, @Param("processName") String processName, @Param("processCode") String processCode,
                                      @Param("reportStartTimeStart") Date reportStartTimeStart, @Param("reportStartTimeEnd") Date reportStartTimeEnd, @Param("reportEndTimeStart") Date reportEndTimeStart,
                                      @Param("reportEndTimeEnd") Date reportEndTimeEnd, @Param("actualReportStartTime") Date actualReportStartTime, @Param("actualReportEndTime") Date actualReportEndTime,
                                      @Param("verifyState") List<String> verifyState, @Param("pricingMethod") List<String> pricingMethod, @Param("ids") List<Integer> ids);

    List<H5WorkReportListResp> getH5WorkReportList(@Param("workOrderCode") String workOrderCode,@Param("produceUser") Integer produceUser);

    IPage<YieldListResp> getYieldForProduct(Page page, @Param(Constants.WRAPPER) Wrapper<YieldListResp> wrapper);

    List<YieldTimeResp> getDateByTime(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("missionIds") String missionIds);

    IPage<YieldListResp> getYieldForProcess(Page page, @Param(Constants.WRAPPER) Wrapper<YieldListResp> wrapper);

    IPage<PerformanceListResp> getPerformance(Page page, @Param(Constants.WRAPPER) Wrapper<PerformanceListResp> wrapper);

    IPage<WagersReportListResp> getWagersReport(Page page, @Param(Constants.WRAPPER) Wrapper<WagersReportListResp> wrapper);

    IPage<BadProductDisResp> getBadProductDistribution(Page page, @Param(Constants.WRAPPER) Wrapper<BadProductDisResp> wrapper);

    List<YieldTimeResp> getDateByTimeOther(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("badProductId") Integer badProductId);

    IPage<BadProductDisDetail> getBadProductDisDetail(Page page, @Param(Constants.WRAPPER) Wrapper<BadProductDisDetail> wrapper);

    IPage<ProduceReportResp> getProduceReportData(Page page, @Param(Constants.WRAPPER) Wrapper<ProduceReportResp> wrapper);

    List<HomeProduceReportResp> getHomeProduceReport();

    List<PerformanceResp> getPerformanceTop5();

    List<BadProductDataResp> getBadProductForData(@Param("startTime") String startTime, @Param("endTime") String endTime);

    List<PerformanceResp> getBadProductForDataA();

    @InterceptorIgnore(tenantLine = "true")
    List<H5WOReportResp> getWorkOrderReport(@Param(Constants.WRAPPER) Wrapper<H5WOReportResp> wrapper, @Param("factoryId") Integer factoryId);

    @InterceptorIgnore(tenantLine = "true")
    ReportDetailResp getReportDetail(@Param("id") Integer id,@Param("factoryId") Integer factoryId);

    @InterceptorIgnore(tenantLine = "true")
    H5ReportDetailResp getH5ReportDetail(@Param("id") Integer id,@Param("factoryId") Integer factoryId);


    List<H5ReportTodayResp> getTodayReport(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("screen") String screen);

    List<Integer> getTodayReportBad(@Param("startTime") Date startTime, @Param("endTime") Date endTime);


    List<H5BadProductResp> getTodayList(@Param("screen") String screen, @Param("workReportIds") List<Integer> workReportIds);

    /**
     * 根据工单编码分组获取良品数
     *
     * @param workCodes 工单编码集合
     */
    List<Map<String, Object>> goodNumGroupByWorkCodes(@Param("workCodes") Set<String> workCodes);

    /**
     * 报工排行统计数据
     *
     * @param param 请求参数
     */
    Page<WorkReportStatisticsVo> workReportStatistics(Page<WorkReport> page, @Param("param") WorkerRankDetailQuery param);

    /**
     * 不良品占比统计数据
     *
     * @param param 请求参数
     */
    List<BadProductRateStatisticsVo> badProductStatistics(Page<ReportBadProduct> page, @Param("param") GetAllQuery param);

    /**
     * H5看板播报
     *
     * @param param 请求参数
     */
    Page<BroadcastVo> broadcast(Page<WorkReport> page, @Param("param") GetAllQuery param);

    /**
     * 不良品分布详情
     *
     * @param param 请求参数
     */
    Page<BadProductRateStatisticsVo> badProductDistributed(Page<WorkReport> page, @Param("param") BadProductDistributedQuery param);

    Page<ReportGroupProcessInfo> workReportGroupByProcessList(Page<WorkReport> page, @Param("query") WorkReportGroupByProcessQuery query);

    List<WorkReportDetailVo> workReportListByProcessCodes(@Param("query") WorkReportGroupByProcessQuery query);

    /**
     * 报工列表
     *
     * @param page  分页
     * @param query 请求参数
     */
    Page<WorkReportListResp> getWorkReportList(Page<WorkReport> page, @Param("query") WorkReportListVo query);

    List<GroupCountVo> getTypeCountMap(@Param("query") WorkReportListVo query, @Param("groupColumn") String groupColumn);

    long getGroupCountVo(@Param("query") WorkReportListVo query);

    Page<ProduceReportResp> getProduceReportList(Page<WorkReport> page, @Param("searchCondition") ProduceReportListVo searchCondition);
}
